﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 异常
{
    class Program
    {
        static void Main(string[] args)
        {
           /* try
            {
                Console.WriteLine("Convert 之前");
                //    int i = Convert.ToInt32("123");
                int i = Convert.ToInt32("abc");
                Console.WriteLine("Convert 之后");
            }
            catch (Exception ex)
            {
                Console.WriteLine("数据错误:"+ex.Message+"\n异常堆栈:"+ex.StackTrace);
            }
            Console.WriteLine("结束之前");*/

            try
            {
                Console.WriteLine(GetAgeDes(-1));
            }
            catch (Exception ex)
            {
                Console.WriteLine("异常信息:"+ex.Message);
            }
            Console.ReadKey();
        }

        static string GetAgeDes(int age)
        {
            if (age < 0)
            {
                throw new Exception("你来自反物质世界啊！");
            }
            else if (age >= 0 && age <= 3)
            {
                return "幼儿";
            }
            else if (age > 3 && age < 18)
            {
                return "青少年";
            }
            else if (age >= 18 && age < 150)
            {
                return "成年人";
            }
            else
            {
                throw new Exception("你见过老佛爷吧！");
            }
        }
    }
}
